/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  cn.hutool.core.util.ObjectUtil
 *  com.alibaba.fastjson.JSON
 *  de.felixroske.jfxsupport.FXMLController
 *  javafx.beans.value.ChangeListener
 *  javafx.beans.value.ObservableValue
 *  javafx.collections.FXCollections
 *  javafx.collections.ObservableList
 *  javafx.event.EventHandler
 *  javafx.fxml.FXML
 *  javafx.fxml.Initializable
 *  javafx.scene.Node
 *  javafx.scene.control.Alert
 *  javafx.scene.control.Alert$AlertType
 *  javafx.scene.control.ComboBox
 *  javafx.scene.control.TableCell
 *  javafx.scene.control.TableColumn
 *  javafx.scene.control.TableView
 *  javafx.scene.control.TextField
 *  javafx.scene.control.cell.PropertyValueFactory
 *  javafx.scene.input.KeyCode
 *  javafx.scene.input.KeyEvent
 *  javafx.scene.layout.AnchorPane
 *  javafx.stage.Modality
 *  javafx.stage.Stage
 *  javafx.util.Callback
 *  javafx.util.StringConverter
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 *  org.springframework.beans.factory.annotation.Autowired
 */
package com.gys.controller.addBox;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.gys.GysApplication;
import com.gys.common.business.AddBoxUtil;
import com.gys.common.business.AddClearBoxUtil;
import com.gys.common.data.HttpJson;
import com.gys.common.data.KeyValue;
import com.gys.common.util.CommonUtil;
import com.gys.common.util.SpringUtil;
import com.gys.controller.BaseController;
import com.gys.controller.addBox.AddBoxController;
import com.gys.controller.addBox.AddProductQueryController;
import com.gys.controller.dataManger.ControllerManger;
import com.gys.data.addBox.AddBoxDetailOutData;
import com.gys.data.clearBox.GetClearQueryProductOutData;
import com.gys.view.addBox.AddAddBoxView;
import com.gys.view.addBox.AddProductQueryView;
import de.felixroske.jfxsupport.FXMLController;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.ResourceBundle;
import java.util.Timer;
import java.util.TimerTask;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.control.Alert;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.util.Callback;
import javafx.util.StringConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

@FXMLController
public class AddAddBoxController
extends BaseController
implements Initializable {
    private static final Logger log = LoggerFactory.getLogger(AddAddBoxController.class);
    @FXML
    private TableView<AddBoxDetailOutData> tableView;
    @FXML
    private TableColumn<AddBoxDetailOutData, String> gsidBatchNo;
    @FXML
    private TableColumn<AddBoxDetailOutData, String> normalPrice;
    @FXML
    private TableColumn<AddBoxDetailOutData, String> gsidProId;
    @FXML
    private TableColumn<AddBoxDetailOutData, String> gsidQty;
    @FXML
    private TableColumn<AddBoxDetailOutData, String> gsidBatch;
    @FXML
    private TableColumn<AddBoxDetailOutData, String> indexDetail;
    @FXML
    private TableColumn<AddBoxDetailOutData, String> gsidProName;
    @FXML
    private ComboBox<KeyValue> emp;
    @FXML
    private TextField proParam;
    @FXML
    private AnchorPane pane;
    @Autowired
    private AddBoxController addBoxController;
    @Autowired
    private AddProductQueryController addProductQueryController;
    private ObservableList<AddBoxDetailOutData> observableTableList = FXCollections.observableArrayList(new ArrayList());
    private List<GetClearQueryProductOutData> queryProductOutData = null;

    public void initialize(URL location, ResourceBundle resources) {
        ControllerManger.controllerMap.put(this.getClass().getSimpleName(), this);
        this.emp.setItems(this.addBoxController.gsegNameOptions);
        this.comboxInit(this.emp);
        this.band();
        this.init();
    }

    @Override
    public void init() {
        if (ObjectUtil.isEmpty(this.pane)) {
            return;
        }
        this.emp.setValue(new KeyValue());
        this.observableTableList.clear();
        this.proParam.clear();
        this.queryProductOutData = null;
        new Timer().schedule(new TimerTask(){

            @Override
            public void run() {
                AddAddBoxView view = SpringUtil.getBean(AddAddBoxView.class);
                Stage stage = (Stage)view.getView().getScene().getWindow();
                stage.getScene().setOnKeyReleased((EventHandler)new EventHandler<KeyEvent>(){

                    public void handle(KeyEvent e) {
                        if (e.getCode() == KeyCode.ENTER) {
                            AddAddBoxController.this.queryPro();
                        }
                        e.consume();
                    }
                });
            }
        }, 500L);
    }

    public void comboxInit(ComboBox box) {
        box.converterProperty().set(new StringConverter<KeyValue>(){

            public String toString(KeyValue object) {
                return object.getName();
            }

            public KeyValue fromString(String string) {
                return null;
            }
        });
    }

    private void queryPro() {
        String inputText = this.proParam.getText().trim();
        if (ObjectUtil.isEmpty(inputText) || inputText.length() > 20) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u8f93\u5165\u4e0d\u80fd\u4e3a\u7a7a\u4e14\u957f\u5ea6\u5c0f\u4e8e\u7b49\u4e8e20");
            alert.showAndWait();
            return;
        }
        HashMap<String, Object> param = new HashMap<String, Object>();
        param.put("nameOrCode", inputText);
        param.put("storageArea", "3");
        HttpJson httpJson = AddClearBoxUtil.queryProduct(param);
        if (!httpJson.isSuccess()) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", httpJson.getMsg());
            alert.showAndWait();
            return;
        }
        this.queryProductOutData = JSON.parseArray((String)httpJson.getMsg(), GetClearQueryProductOutData.class);
        if (this.queryProductOutData.size() == 0) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u6ca1\u6709\u67e5\u5230\u6570\u636e");
            alert.showAndWait();
            return;
        }
        this.addProductQueryController.init();
        GysApplication.showView(AddProductQueryView.class, (Modality)Modality.APPLICATION_MODAL);
    }

    @FXML
    private void sureAction() {
        HashMap<String, Object> param = new HashMap<String, Object>();
        String empId = ((KeyValue)this.emp.getValue()).getValue();
        if (ObjectUtil.isEmpty(empId)) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u8bf7\u9009\u62e9\u88c5\u6597\u4eba\u5458");
            alert.showAndWait();
            return;
        }
        if (this.tableView.getItems().size() == 0) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u8bf7\u6dfb\u52a0\u5546\u54c1");
            alert.showAndWait();
            return;
        }
        for (int i = 0; i < this.tableView.getItems().size(); ++i) {
            if (!ObjectUtil.isEmpty(((AddBoxDetailOutData)this.tableView.getItems().get(i)).getGsidQty())) continue;
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u88c5\u6597\u6570\u91cf\u8bf7\u586b\u5199\u5b8c\u6574");
            alert.showAndWait();
            return;
        }
        param.put("emp", empId);
        param.put("addBoxDetailOutDataList", this.tableView.getItems());
        HttpJson httpJson = AddBoxUtil.addAddBox(param);
        if (httpJson.isSuccess()) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u4fdd\u5b58\u6210\u529f");
            alert.showAndWait();
            this.cancelAction();
            this.addBoxController.initTableViewTwo();
        } else {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", httpJson.getMsg());
            alert.showAndWait();
        }
    }

    public void reflsh(AddBoxDetailOutData addBoxDetailOutData) {
        ObservableList items = this.tableView.getItems();
        items.add(addBoxDetailOutData);
        this.observableTableList = FXCollections.observableArrayList((Collection)items);
        this.tableView.setItems(this.observableTableList);
        this.gscdQtyToTextField();
    }

    public void gscdQtyToTextField() {
        this.gsidQty.setCellFactory(tc -> {
            final TextField textField = new TextField();
            textField.setMinHeight(30.0);
            textField.setPrefWidth(90.0);
            TableCell<AddBoxDetailOutData, String> cell = new TableCell<AddBoxDetailOutData, String>(){

                protected void updateItem(String chuzhi, boolean empty) {
                    super.updateItem(chuzhi, empty);
                    if (empty) {
                        this.setGraphic(null);
                    } else {
                        textField.setText(chuzhi);
                        this.setGraphic((Node)textField);
                    }
                }
            };
            textField.textProperty().addListener((ChangeListener)new ChangeListener<String>(){
                final TableCell val_cell;
                {
                    this.val_cell = cell;
                }

                public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
                    int rank = this.val_cell.getIndex();
                    if (ObjectUtil.isNotEmpty(newValue) && !CommonUtil.positiveInteger(newValue)) {
                        Alert alert = AddAddBoxController.this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u8bf7\u8f93\u5165\u6b63\u6574\u6570");
                        alert.showAndWait();
                        return;
                    }
                    ((AddBoxDetailOutData)AddAddBoxController.this.observableTableList.get(rank)).setGsidQty(newValue);
                }
            });
            return cell;
        });
    }

    private void band() {
        this.gsidBatchNo.setCellValueFactory((Callback)new PropertyValueFactory(this.gsidBatchNo.getId()));
        this.normalPrice.setCellValueFactory((Callback)new PropertyValueFactory(this.normalPrice.getId()));
        this.gsidProId.setCellValueFactory((Callback)new PropertyValueFactory(this.gsidProId.getId()));
        this.gsidQty.setCellValueFactory((Callback)new PropertyValueFactory(this.gsidQty.getId()));
        this.gsidBatch.setCellValueFactory((Callback)new PropertyValueFactory(this.gsidBatch.getId()));
        this.indexDetail.setCellValueFactory((Callback)new PropertyValueFactory(this.indexDetail.getId()));
        this.gsidProName.setCellValueFactory((Callback)new PropertyValueFactory(this.gsidProName.getId()));
    }

    @FXML
    private void cancelAction() {
        this.pane.getScene().getWindow().hide();
    }

    public TableView<AddBoxDetailOutData> getTableView() {
        return this.tableView;
    }

    public TableColumn<AddBoxDetailOutData, String> getGsidBatchNo() {
        return this.gsidBatchNo;
    }

    public TableColumn<AddBoxDetailOutData, String> getNormalPrice() {
        return this.normalPrice;
    }

    public TableColumn<AddBoxDetailOutData, String> getGsidProId() {
        return this.gsidProId;
    }

    public TableColumn<AddBoxDetailOutData, String> getGsidQty() {
        return this.gsidQty;
    }

    public TableColumn<AddBoxDetailOutData, String> getGsidBatch() {
        return this.gsidBatch;
    }

    public TableColumn<AddBoxDetailOutData, String> getIndexDetail() {
        return this.indexDetail;
    }

    public TableColumn<AddBoxDetailOutData, String> getGsidProName() {
        return this.gsidProName;
    }

    public ComboBox<KeyValue> getEmp() {
        return this.emp;
    }

    public TextField getProParam() {
        return this.proParam;
    }

    public AnchorPane getPane() {
        return this.pane;
    }

    public AddBoxController getAddBoxController() {
        return this.addBoxController;
    }

    public AddProductQueryController getAddProductQueryController() {
        return this.addProductQueryController;
    }

    public ObservableList<AddBoxDetailOutData> getObservableTableList() {
        return this.observableTableList;
    }

    public List<GetClearQueryProductOutData> getQueryProductOutData() {
        return this.queryProductOutData;
    }

    public void setTableView(TableView<AddBoxDetailOutData> tableView) {
        this.tableView = tableView;
    }

    public void setGsidBatchNo(TableColumn<AddBoxDetailOutData, String> gsidBatchNo) {
        this.gsidBatchNo = gsidBatchNo;
    }

    public void setNormalPrice(TableColumn<AddBoxDetailOutData, String> normalPrice) {
        this.normalPrice = normalPrice;
    }

    public void setGsidProId(TableColumn<AddBoxDetailOutData, String> gsidProId) {
        this.gsidProId = gsidProId;
    }

    public void setGsidQty(TableColumn<AddBoxDetailOutData, String> gsidQty) {
        this.gsidQty = gsidQty;
    }

    public void setGsidBatch(TableColumn<AddBoxDetailOutData, String> gsidBatch) {
        this.gsidBatch = gsidBatch;
    }

    public void setIndexDetail(TableColumn<AddBoxDetailOutData, String> indexDetail) {
        this.indexDetail = indexDetail;
    }

    public void setGsidProName(TableColumn<AddBoxDetailOutData, String> gsidProName) {
        this.gsidProName = gsidProName;
    }

    public void setEmp(ComboBox<KeyValue> emp) {
        this.emp = emp;
    }

    public void setProParam(TextField proParam) {
        this.proParam = proParam;
    }

    public void setPane(AnchorPane pane) {
        this.pane = pane;
    }

    public void setAddBoxController(AddBoxController addBoxController) {
        this.addBoxController = addBoxController;
    }

    public void setAddProductQueryController(AddProductQueryController addProductQueryController) {
        this.addProductQueryController = addProductQueryController;
    }

    public void setObservableTableList(ObservableList<AddBoxDetailOutData> observableTableList) {
        this.observableTableList = observableTableList;
    }

    public void setQueryProductOutData(List<GetClearQueryProductOutData> queryProductOutData) {
        this.queryProductOutData = queryProductOutData;
    }

    public boolean equals(Object o) {
        if (o == this) {
            return true;
        }
        if (!(o instanceof AddAddBoxController)) {
            return false;
        }
        AddAddBoxController other = (AddAddBoxController)o;
        if (!other.canEqual(this)) {
            return false;
        }
        TableView<AddBoxDetailOutData> this$tableView = this.getTableView();
        TableView<AddBoxDetailOutData> other$tableView = other.getTableView();
        if (this$tableView == null ? other$tableView != null : !this$tableView.equals(other$tableView)) {
            return false;
        }
        TableColumn<AddBoxDetailOutData, String> this$gsidBatchNo = this.getGsidBatchNo();
        TableColumn<AddBoxDetailOutData, String> other$gsidBatchNo = other.getGsidBatchNo();
        if (this$gsidBatchNo == null ? other$gsidBatchNo != null : !this$gsidBatchNo.equals(other$gsidBatchNo)) {
            return false;
        }
        TableColumn<AddBoxDetailOutData, String> this$normalPrice = this.getNormalPrice();
        TableColumn<AddBoxDetailOutData, String> other$normalPrice = other.getNormalPrice();
        if (this$normalPrice == null ? other$normalPrice != null : !this$normalPrice.equals(other$normalPrice)) {
            return false;
        }
        TableColumn<AddBoxDetailOutData, String> this$gsidProId = this.getGsidProId();
        TableColumn<AddBoxDetailOutData, String> other$gsidProId = other.getGsidProId();
        if (this$gsidProId == null ? other$gsidProId != null : !this$gsidProId.equals(other$gsidProId)) {
            return false;
        }
        TableColumn<AddBoxDetailOutData, String> this$gsidQty = this.getGsidQty();
        TableColumn<AddBoxDetailOutData, String> other$gsidQty = other.getGsidQty();
        if (this$gsidQty == null ? other$gsidQty != null : !this$gsidQty.equals(other$gsidQty)) {
            return false;
        }
        TableColumn<AddBoxDetailOutData, String> this$gsidBatch = this.getGsidBatch();
        TableColumn<AddBoxDetailOutData, String> other$gsidBatch = other.getGsidBatch();
        if (this$gsidBatch == null ? other$gsidBatch != null : !this$gsidBatch.equals(other$gsidBatch)) {
            return false;
        }
        TableColumn<AddBoxDetailOutData, String> this$indexDetail = this.getIndexDetail();
        TableColumn<AddBoxDetailOutData, String> other$indexDetail = other.getIndexDetail();
        if (this$indexDetail == null ? other$indexDetail != null : !this$indexDetail.equals(other$indexDetail)) {
            return false;
        }
        TableColumn<AddBoxDetailOutData, String> this$gsidProName = this.getGsidProName();
        TableColumn<AddBoxDetailOutData, String> other$gsidProName = other.getGsidProName();
        if (this$gsidProName == null ? other$gsidProName != null : !this$gsidProName.equals(other$gsidProName)) {
            return false;
        }
        ComboBox<KeyValue> this$emp = this.getEmp();
        ComboBox<KeyValue> other$emp = other.getEmp();
        if (this$emp == null ? other$emp != null : !this$emp.equals(other$emp)) {
            return false;
        }
        TextField this$proParam = this.getProParam();
        TextField other$proParam = other.getProParam();
        if (this$proParam == null ? other$proParam != null : !this$proParam.equals(other$proParam)) {
            return false;
        }
        AnchorPane this$pane = this.getPane();
        AnchorPane other$pane = other.getPane();
        if (this$pane == null ? other$pane != null : !this$pane.equals(other$pane)) {
            return false;
        }
        AddBoxController this$addBoxController = this.getAddBoxController();
        AddBoxController other$addBoxController = other.getAddBoxController();
        if (this$addBoxController == null ? other$addBoxController != null : !(this$addBoxController).equals(other$addBoxController)) {
            return false;
        }
        AddProductQueryController this$addProductQueryController = this.getAddProductQueryController();
        AddProductQueryController other$addProductQueryController = other.getAddProductQueryController();
        if (this$addProductQueryController == null ? other$addProductQueryController != null : !(this$addProductQueryController).equals(other$addProductQueryController)) {
            return false;
        }
        ObservableList<AddBoxDetailOutData> this$observableTableList = this.getObservableTableList();
        ObservableList<AddBoxDetailOutData> other$observableTableList = other.getObservableTableList();
        if (this$observableTableList == null ? other$observableTableList != null : !this$observableTableList.equals(other$observableTableList)) {
            return false;
        }
        List<GetClearQueryProductOutData> this$queryProductOutData = this.getQueryProductOutData();
        List<GetClearQueryProductOutData> other$queryProductOutData = other.getQueryProductOutData();
        return !(this$queryProductOutData == null ? other$queryProductOutData != null : !(this$queryProductOutData).equals(other$queryProductOutData));
    }

    protected boolean canEqual(Object other) {
        return other instanceof AddAddBoxController;
    }

    public int hashCode() {
        int PRIME = 59;
        int result = 1;
        TableView<AddBoxDetailOutData> $tableView = this.getTableView();
        result = result * 59 + ($tableView == null ? 43 : $tableView.hashCode());
        TableColumn<AddBoxDetailOutData, String> $gsidBatchNo = this.getGsidBatchNo();
        result = result * 59 + ($gsidBatchNo == null ? 43 : $gsidBatchNo.hashCode());
        TableColumn<AddBoxDetailOutData, String> $normalPrice = this.getNormalPrice();
        result = result * 59 + ($normalPrice == null ? 43 : $normalPrice.hashCode());
        TableColumn<AddBoxDetailOutData, String> $gsidProId = this.getGsidProId();
        result = result * 59 + ($gsidProId == null ? 43 : $gsidProId.hashCode());
        TableColumn<AddBoxDetailOutData, String> $gsidQty = this.getGsidQty();
        result = result * 59 + ($gsidQty == null ? 43 : $gsidQty.hashCode());
        TableColumn<AddBoxDetailOutData, String> $gsidBatch = this.getGsidBatch();
        result = result * 59 + ($gsidBatch == null ? 43 : $gsidBatch.hashCode());
        TableColumn<AddBoxDetailOutData, String> $indexDetail = this.getIndexDetail();
        result = result * 59 + ($indexDetail == null ? 43 : $indexDetail.hashCode());
        TableColumn<AddBoxDetailOutData, String> $gsidProName = this.getGsidProName();
        result = result * 59 + ($gsidProName == null ? 43 : $gsidProName.hashCode());
        ComboBox<KeyValue> $emp = this.getEmp();
        result = result * 59 + ($emp == null ? 43 : $emp.hashCode());
        TextField $proParam = this.getProParam();
        result = result * 59 + ($proParam == null ? 43 : $proParam.hashCode());
        AnchorPane $pane = this.getPane();
        result = result * 59 + ($pane == null ? 43 : $pane.hashCode());
        AddBoxController $addBoxController = this.getAddBoxController();
        result = result * 59 + ($addBoxController == null ? 43 : ($addBoxController).hashCode());
        AddProductQueryController $addProductQueryController = this.getAddProductQueryController();
        result = result * 59 + ($addProductQueryController == null ? 43 : ($addProductQueryController).hashCode());
        ObservableList<AddBoxDetailOutData> $observableTableList = this.getObservableTableList();
        result = result * 59 + ($observableTableList == null ? 43 : $observableTableList.hashCode());
        List<GetClearQueryProductOutData> $queryProductOutData = this.getQueryProductOutData();
        result = result * 59 + ($queryProductOutData == null ? 43 : ($queryProductOutData).hashCode());
        return result;
    }

    public String toString() {
        return "AddAddBoxController(tableView=" + this.getTableView() + ", gsidBatchNo=" + this.getGsidBatchNo() + ", normalPrice=" + this.getNormalPrice() + ", gsidProId=" + this.getGsidProId() + ", gsidQty=" + this.getGsidQty() + ", gsidBatch=" + this.getGsidBatch() + ", indexDetail=" + this.getIndexDetail() + ", gsidProName=" + this.getGsidProName() + ", emp=" + this.getEmp() + ", proParam=" + this.getProParam() + ", pane=" + this.getPane() + ", addBoxController=" + this.getAddBoxController() + ", addProductQueryController=" + this.getAddProductQueryController() + ", observableTableList=" + this.getObservableTableList() + ", queryProductOutData=" + this.getQueryProductOutData() + ")";
    }
}

